import { onUnmounted, ref } from "vue";
import { CENSUS_INTERVAL } from "@/utils/constant";

export function useInterVal() {
    let timer = null;
    const isFlag = ref(false);
    onUnmounted(() => {
        clearInterval(timer);
    });

    function setsInterVal(fn) {
        fn();
        isFlag.value = true;
        timer = setInterval(() => {
            fn();
        }, CENSUS_INTERVAL);
    }
    function clearsInterval() {
        clearInterval(timer);
    }
    return {
        setsInterVal,
        clearsInterval,
        isFlag
    };
}
